import instace from "../request";
import type { Ref } from "vue";
import qs from 'qs'

// productAttribute/category/list
// 分页获取所有商品属性分类
interface productAttrParams {
  pageNum?: number | Ref<number>;
  pageSize?: number | Ref<number>;
  cid?: number | Ref<number>;
  type?: number | Ref<number>;
}

interface productAttrItem {
  attributeCount?: number;
  id: number;
  name: string;
  paramCount?: number;
  filterType: number;
  handAddStatus: number;
  inputList: string;
  inputType: number;
  productAttributeCategoryId: number;
  relatedStatus: number;
  searchType: number;
  selectType: number;
  sort: number;
  type: number;
}

interface productAttrRes {
  list: productAttrItem[];
  pageNum: number;
  pageSize: number;
  total: number;
  totalPage: number;
}

const getproductAttrList = (
  data?: productAttrParams
): Promise<productAttrRes> => {
  return instace.get("/productAttribute/category/list", {
    params: data,
  });
};

// /productAttribute/category/create
// 添加商品属性分类
interface addproductAttrParams {
  name?: string | Ref<string>;
}
const addproductAttr = (data: addproductAttrParams) => {
  return instace.post("/productAttribute/category/create", qs.stringify(data));
};

// /productAttribute/category/update/{id}
// 修改商品属性分类
interface upproductAttrParams {
  name?: string | Ref<string>;
  id?: number | Ref<number>;
}
const upproductAttr = (data: upproductAttrParams) => {
  return instace.post(
    `/productAttribute/category/update/${data.id}`,
    qs.stringify(data)
  );
};
// /productAttribute/category/delete/{id}
// 删除单个商品属性分类
const deleteproductAttr = (id: number) => {
  return instace.get(`/productAttribute/category/delete/${id}`);
};

/**
 * /productAttribute/list/{cid}
根据分类查询属性列表或参数列表
 * */
const getclassifyproductAttributelist = (
  data: productAttrParams
): Promise<productAttrRes> => {
  return instace.get(`/productAttribute/list/${data.cid}`, {
    params: data,
  });
};

// /productAttribute/update/{id}
// 修改商品属性信息
const productAttributeupdate = (data: productAttrItem) => {
  return instace.post(`/productAttribute/update/${data.id}`, data);
};
// /productAttribute/create
// 添加商品属性信息
const productAttributeadddata = (data: productAttrItem) => {
  return instace.post("/productAttribute/create", data);
};

// /productAttribute/delete
// 批量删除商品属性
const productAttributedelete = (aaa: string) => {
  return instace.post("/productAttribute/delete", qs.stringify({ids:aaa}));
};

export {
  getproductAttrList,
  addproductAttr,
  upproductAttr,
  deleteproductAttr,
  getclassifyproductAttributelist,
  productAttributeupdate,
  productAttributeadddata,
  productAttributedelete,
};
export type { productAttrParams, productAttrItem, productAttrRes };
